//
// Created by Semir on 2020/5/9.
//

//TODO Review
#include <iostream>
#include <vector>

using namespace std;

int minNumberInRotateArray(vector<int> rotateArray) {
    int low = 0;
    int high = rotateArray.size() - 1;
    if (rotateArray[low] < rotateArray[high]) {
        return rotateArray[low];
    }
    int mid = 0;
    while (low <= high) {
        mid = ((high - low) >> 1) + low;
        if (mid == 0) {
            return rotateArray[mid + 1];
        }
        if (rotateArray[mid - 1] > rotateArray[mid]) {
            return rotateArray[mid];
        } else if (rotateArray[mid] > rotateArray[high]) {
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
    return -1;
}

int main() {
    vector<int> arr = {2,3,4,2,2};
    int res = minNumberInRotateArray(arr);
    cout << res << endl;
    return 0;
}